﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>管理后台</title>
    <link rel="stylesheet" href="../../../static/admin/layui/css/layui.css" media="all"/>
    <link rel="stylesheet/less" href="../../../static/admin/css/index.less"/>
    <link rel="stylesheet" href="../../../static/admin/css/jquery.pagination.css"/>
    <script src="../../../static/admin/js/jquery-1.12.3.js"></script>
    <script src="../../../static/admin/layui/layui.js"></script>
    <script src="../../../static/admin/js/less.min.js"></script>
    <script src="../../../static/admin/js/jquery.pagination.min.js"></script>
    <script src="../../../static/layer/layer.js"></script>
</head>
<style>
    .content img {
        width: 3rem;
    }

    img:hover {
        transform: scale(2, 2);
        transition: .5s transform;
    }
</style>

<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    {% include "/admin/left.html" %}

    <div class="layui-body">
        <div id="box" class="fl">
            <div class="content">
                <h3>新闻列表</h3>
                <div class="search">
                    <label>分享类型：</label>
                    <select id="share_type">
                        <option value="">请选择</option>
                        <option value="1">新闻</option>
                        <option value="3">视频</option>
                        <option value="2">图片</option>
                    </select>
                    <label>选择类型：</label>
                    <select style="margin-left: 0" id="news_type">
                        <option value="">请选择</option>
                        {% if c_type %}
                        {% for d in c_type %}
                        <option value="{{ d.tid }}">{{ d.type_name }}</option>
                        {% endfor %}
                        {% endif %}
                    </select>
                    <button onclick="get_data(1)" class="s_button">搜索</button>
                </div>

                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <thead>
                    <tr>
                        <th style="width: 10%;">ID</th>
                        <th style="width: 25%;">标题</th>
                        <th style="width: 10%;">类型</th>
                        <th style="width: 10%;">分享类型</th>
                        <th>发布时间</th>
                        <th>操作</th>
                    </tr>
                    </tbody>
                    <tbody id="result">
                    </tbody>
                </table>

            </div>
            <div id="pagination1" class="page fr" style="margin-right: 1%;">
                <div class="ui-pagination-container">
                </div>
            </div>
        </div>

    </div>
</div>
<input type="hidden" value="1" id="p">
<script>
    //JavaScript代码区域
    layui.use('element', function () {
        var element = layui.element;

    });
</script>
</body>

</html>

<script>
    get_data(1);
    function get_data(p){
        var share_type = $('#share_type').val();
        var news_type = $('#news_type').val();
        $.ajax({
            url:"/admin/news_list_post",
            type:"post",
            data:{
                'p':p,
                'share_type':share_type,
                'news_type':news_type
            },
            dataType:"json",
            success:function(msg){
                var q = '';
                if (msg.status == 1){
                    for (var i = 0; i < msg.res.length; i++){
                        q += '<tr>';
                        q += '<td>' + msg.res[i].id + '</td>';
                        q += '<td><a target="_blank" href="' + msg.res[i].url + '">' + msg.res[i].title + '</a></td>';
                        q += '<td>' + msg.res[i].type_name + '</td>';
                        if (msg.res[i].share_type == 1){
                            q += '<td>新闻</td>';
                        }else if(msg.res[i].share_type == 2){
                            q += '<td>图片</td>';
                        }else{
                            q += '<td>视频</td>';
                        }
                        q += '<td>' + msg.res[i].publish_time + '</td>';
                        q += '<td>';
                        q += ' <button><a onclick="btn_fb('+ msg.res[i].id + ')" class="course_commit"  name="edit">删除</a></button>';
                        q += '</td>';
                        q += '</tr>';
                    }
                }else {
                    q += '<tr><td colspan="6">暂无数据</td></tr>';
                }
                $('#result').html(q);
                $('.ui-pagination-container').html(msg.page);
                $('#p').val(msg.p);
            }
        })
    }
    function btn_fb(uid){
        layer.open({
            content: "确定删除",
            btn: ['确定', '取消'],
            shadeClose: false,
            yes: function () {
                $.ajax({
                    type: 'post',
                    url: '/admin/delete_news_post',
                    data: {
                        uid : uid
                    },
                    success: function (msg) {
                        if (msg.status == 1) {
                            layer.msg("操作成功", {time: 2000}, function () {
                                get_data($('#p').val());
                            });
                        } else {
                            layer.msg("操作失败", {time:1200})
                        }
                    }
                });
            }
        })
    }

</script>
